const express = require('express');
const router = express.Router();
const UserInfo_handler = require('../router_handle/userinfo');
const multer = require('multer');   //用于处理multipart/form-data 类型表单数据的中间件
const storage = multer.diskStorage({ //multer的存储引擎，可以对上传文件进行更多的控制
  destination: function (req, file, cb) {//保存路径
    cb(null, 'uploads/');
  },
  filename: function (req, file, cb) {//重命名
    console.log(file);
    cb(null, Buffer.from(file.originalname, 'latin1').toString('utf8'));//buffer From 将获取到的数据流以latin1
  }
});
const upload = multer({ storage: storage });

//修改头像  single()接受单个文件
router.post('/headPicture', upload.single('file'), UserInfo_handler.changeHeadPicture);
router.get('/getheadPicture', UserInfo_handler.getHeadPicture)
router.post('/changePassword', UserInfo_handler.changePassword)
router.post('/changeBgImg', upload.single('file'), UserInfo_handler.changeBgImg)
module.exports = router